package com.example.shuiyinceshi


import android.graphics.BitmapFactory
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import android.widget.Toast


class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        var permissionUtils=PermissionUtils()
        permissionUtils.verifyStoragePermissions(this)
        permissionUtils.verifyStoragePermissions2(this)


        var imageView2=findViewById<ImageView>(R.id.imageView2)



        var button1=findViewById<Button>(R.id.button)
        button1.setOnClickListener {



            permissionUtils.verifyStoragePermissions(this)
            permissionUtils.verifyStoragePermissions2(this)

            if(permissionUtils.REQUEST_EXTERNAL_STORAGE==1)
            {
                Toast.makeText(applicationContext,"error",Toast.LENGTH_LONG).show()
                //return@setOnClickListener;
            }
            if(permissionUtils.REQUEST_EXTERNAL_STORAGE==1)
            {
                Toast.makeText(applicationContext,"error2",Toast.LENGTH_LONG).show()
                //return@setOnClickListener;
            }

            var myFFmpegKit=MyFFmpegKit()
            //myFFmpegKit.imageaddtxt()
            myFFmpegKit.getbitrate()


            var image1=BitmapFactory.decodeFile("/storage/emulated/0/1/2.jpg")
            if (image1==null)
            {
                Toast.makeText(applicationContext,"image null"+applicationContext.getExternalCacheDir()?.getPath(),Toast.LENGTH_LONG).show()
            }
            imageView2.setImageBitmap(image1)

            //var session=FFmpegKit.execute("-i /storage/emulated/0/1/1.jpg -vf drawtext=text='Watermark':fontfile='/storage/emulated/0/Android/data/com.example.shuiyinceshi/cache/arial.ttf':x=10:y=10:fontsize=12:fontcolor=white:shadowy=2 /storage/emulated/0/1/2.jpg")

            /*
            var session=FFmpegKit.execute("-i /storage/emulated/0/1/m.mp4 " +
                    "-vf drawtext=text='Watermark':fontfile='/storage/emulated/0/Android/data/com.example.shuiyinceshi/cache/arial.ttf':" +
                    "x=10:y=h-300:fontsize=48:fontcolor=white:shadowy=2 " +
                    "-c:a copy /storage/emulated/0/1/m2.mp4")

             */

            /*

            var rc=FFmpeg.execute("-i "+applicationContext.getExternalCacheDir()?.getPath()+"/1.jpg -vf" +
                    "drawtext=text=12345678:fontcolor=white:fontsize=24:x=(w-text_w)/2:y=(h-text_h)/2"+
                    applicationContext.getExternalCacheDir()?.getPath()+"/2.jpg")
             */
            /*
            var rc=FFmpeg.execute("-i "+applicationContext.getExternalCacheDir()?.getPath()+"/1.jpg -vf " +
                    "drawtext=text='Watermark':x=10:y=10:fontsize=12:fontcolor=white:shadowy=2 "+
                    "-codec:a copy " +
                    applicationContext.getExternalCacheDir()?.getPath()+"/2.jpg")

            */

            //var rc=FFmpeg.execute("-i /storage/emulated/0/Android/data/com.example.shuiyinceshi/cache/1.jpg -i /storage/emulated/0/Android/data/com.example.shuiyinceshi/cache/11.jpeg -filter_complex overlay=10:10 -c:a copy /storage/emulated/0/Android/data/com.example.shuiyinceshi/cache/2.jpg")

            //var rc=FFmpeg.execute("-i /storage/emulated/0/1/m.mp4 -vf \"drawtext=text='Watermark':x=10:y=10:fontsize=12:fontcolor=white:shadowy=12\" -codec:a copy /storage/emulated/0/1/m1.mp4")

            //"drawtext=text=12345678:fontcolor=white:fontsize=24:x=(w-text_w)/2:y=(h-text_h)/2"

        }









    }
}